/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Datos;

import Entidades.Usuario;
import Interfaces.IUsuario;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HOUSE
 */
public class DBUsuario implements IUsuario{
    Connection conexion;
    public Connection getConection() {
       if (conexion == null) {
           try {
               Driver driver = new com.mysql.jdbc.Driver();
               DriverManager.registerDriver(driver);
               conexion = DriverManager.getConnection("jdbc:mysql://db4free.net/edfisica", "noxus2014", "noxu12345");
               System.out.println("conectado");
           } catch (SQLException ex) {
               ex.printStackTrace();
               Logger.getLogger(DBUsuario.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("no se pudo conectar");
           }
       }
       return conexion;
   }

    @Override
    public boolean IngresaUsuario(Usuario nodo) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean ModificaUsuario(Usuario nodo) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean EliminaUsuario(int IDUsuario) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<Usuario> ListaUsuario() {
        ArrayList<Usuario> per = new ArrayList<Usuario>();
       try {
           CallableStatement statement;
            statement =getConection().prepareCall("{call ListaUsuarios}");
           ResultSet resultSet = statement.executeQuery();
           while (resultSet.next()) {
               Usuario reglam= new Usuario();
              
               reglam.setIDUsuario(resultSet.getInt(1));
               reglam.setNomUsuario(resultSet.getString(2));
               reglam.setPass(resultSet.getString(3));
               reglam.setrol(resultSet.getInt(4));
               
               
               per.add(reglam);
              
           }
           return per;
       } catch (SQLException ex) {
           ex.printStackTrace();
           return null;
       }
    }
    
}
